package com.lib.framework.utils

import android.net.Uri

/**
 * Copyright (C), 2020-2020, 享物说
 * FileName: StringUtil
 * Author: keanbin
 * Date: 2020-02-06 16:13
 * Description: 字符串工具类
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
class StringUtil {

    companion object {

        /**
         * 字符串全部匹配正则规则
         */
        fun regexMatches(str: String, format: String) = Regex(format).matches(str)


        /**
         * url to Uri
         */
        @JvmStatic
        fun parseUri(url: String?): Uri? {
            return try {
                Uri.parse(url)
            } catch (e: Exception) {
                null
            }
        }

        fun isBoolean(value: String?): Boolean {
            return try {
                "true" == value || "false" == value
            } catch (e: java.lang.Exception) {
                false
            }
        }

        fun isInteger(value: String?): Boolean {
            return try {
                Integer.valueOf(value!!)
                true
            } catch (e: java.lang.Exception) {
                false
            }
        }

        fun isLong(value: String?): Boolean {
            return try {
                java.lang.Long.valueOf(value!!)
                true
            } catch (e: java.lang.Exception) {
                false
            }
        }

        fun isDouble(value: String?): Boolean {
            return try {
                java.lang.Double.valueOf(value!!)
                true
            } catch (e: java.lang.Exception) {
                false
            }
        }

        fun isIntegerForDouble(obj: Double): Boolean {
            val eps = 1e-10
            return obj - Math.floor(obj) < eps
        }
    }
}